CC=gcc
CFLAGS=-g -W -Wall -ansi -pedantic --std=c99 -lncurses
LDFLAGS=-lpthread -lncurses
EXEC=server client
OBJDIR = obj
SRC = $(wildcard *.c)
OBJ = $(SRC:.c=.o)
OBJ := $(addprefix $(OBJDIR)/, $(OBJ))

all: $(EXEC)

server: server.o clienthandler.o
	$(CC) -o $@ $^ $(LDFLAGS)

client: client.o
	$(CC) -o $@ $^ $(LDFLAGS)

$(OBJDIR)/fonctions.o: fonctions.h
$(OBJDIR)/clienthandler.o: clienthandler.h

$(OBJDIR)/%.o: %.c
	@if [ ! -d obj ] ;then mkdir obj ;fi
	@$(CC) -o $@ -c $< $(CFLAGS)

.PHONY: clean mrproper

clean:
	@rm -rf $(OBJDIR);

mrproper:
	@rm -rf $(EXEC)

